﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>

<script runat="server">



    Models.DAO.ClaimDAO cldao = new Models.DAO.ClaimDAO();
    System.Data.DataTable dt = new System.Data.DataTable();
    //Models.DAO.DonViBHDAO dv = new Models.DAO.DonViBHDAO();
    //Models.DAO.GiaiDoanDAO gd = new Models.DAO.GiaiDoanDAO();
    //Models.DAO.GiamDinhVienDAO gdvdao = new Models.DAO.GiamDinhVienDAO();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            loadPending();
            //loadMaHoa();
            //loadStatus();
            //loadGDV();

            //if (Session["MaGDV"] == null)
            //    Response.Redirect("~/Pages/Login.aspx");
            //else
            //{
            //    loadPending();
            //    //loadMaHoa();
            //    loadStatus();
            //    loadGDV();

            //}
        }
    }
    //void loadStatus()
    //{
    //    System.Data.DataTable dt = new System.Data.DataTable();
    //    //dt = gd.DSGiaiDoan();
    //    drStatus.DataSource = dt;
    //    drStatus.DataTextField = "TenGiaiDoan";
    //    drStatus.DataValueField = "ID_GiaiDoanHoanThanh";
    //    drStatus.DataBind();
    //}
    //void loadMaHoa()
    //{
    //    DataTable dt = new DataTable();
    //    dt = dv.DSDVMaHoa();
    //    drDonViBH.DataSource = dt;
    //    drDonViBH.DataValueField = "ID_DonVi";
    //    drDonViBH.DataTextField = "MaHoa";
    //    drDonViBH.DataBind();
    //}
    //void loadTheoMaHoa(string mahoa)
    //{
    //    DataTable dt = new DataTable();
    //    dt = cldao.SelectClaimMaHoa(mahoa);
    //    grDSClaim.DataSource = dt;
    //    grDSClaim.DataBind();
    //}
    //void loadTheoStatus(int magd)
    //{
    //    DataTable dt = new DataTable();
    //    dt = cldao.DSClaimTheoStatus(magd);
    //    grDSClaim.DataSource = dt;
    //    grDSClaim.DataBind();
    //}
    void loadPending()
    {
        System.Data.DataTable dt = cldao.SelectPending();
        if (dt.Rows.Count > 0)
        {
            grDSClaim.DataSource = dt;
            grDSClaim.DataBind();
            lblThongBao.Visible = false;
        }
        else
        {
            lblThongBao.Visible = true;
            lblThongBao.Text = "Không có Case đang pending!";
        }
    }
    ////void loadDS()
    ////{
    ////    dt = cldao.DSClaimDangGiamDinh();
    ////    if (dt.Rows.Count > 0)
    ////    {
    ////        grDSClaim.DataSource = dt;
    ////        grDSClaim.DataBind();
    ////        int so = dt.Rows.Count;
    ////        lblThongBao.Visible = false;
    ////    }
    ////    else
    ////    {
    ////        lblThongBao.Text = "Hiện không có Claim đang giám định!!!  ";
    ////        lblThongBao.Visible = true;
    ////    }
    ////}
    //Models.DAO.GiaiDoanDAO gddao = new Models.DAO.GiaiDoanDAO();

    //protected void loadGiaiDoan()
    //{
    //    drStatus.DataSource = gddao.DSGiaiDoan();
    //    drStatus.DataTextField = "TenGiaiDoan";
    //    drStatus.DataValueField = "ID_GiaiDoanHoanThanh";
    //    drStatus.DataBind();
    //}

    //protected void btnTiemKiem_Click(object sender, EventArgs e)
    //{

    //    string mathamchieu = txtThamChieu.Text;
    //    bool kq = cldao.KiemTraThamChieu(mathamchieu);
    //    if (kq == true)
    //    {
    //        Session["ThamChieu"] = mathamchieu;
    //        //Response.Redirect("~/Pages/ManageClaim.aspx?thamchieu=" + mathamchieu);
    //        //Response.Redirect("~/Pages/InformationForm.aspx?Reference="+mathamchieu);
    //        Response.Redirect("~/Pages/ClaimDetail1.aspx?Ref=Cover");
    //    }
        
    //}

    //protected void grDSClaim_PageIndexChanging(object sender, GridViewPageEventArgs e)
    //{
    //    grDSClaim.PageIndex = e.NewPageIndex;
    //    loadPending();
    //}
    //bool CheckPub(int GDV, string idclaim)
    //{
    //    int PUBGDV = gdvdao.LayMaPub(GDV);
    //    int PUBCLAIM = cldao.LayMaPUB(idclaim);
    //    bool kt = false;
    //    if (PUBGDV == 1)
    //        kt = true;
    //    else
    //        if (PUBGDV == 2 && PUBGDV == PUBCLAIM)
    //            kt = true;
    //        else
    //            if (PUBGDV == 3 && PUBGDV == PUBCLAIM)
    //                kt = true;
    //    return kt;
    //}
    //protected void grDSClaim_SelectedIndexChanged(object sender, EventArgs e)
    //{
    //    GridViewRow row = grDSClaim.SelectedRow;
    //    if (row != null)
    //    {
    //        //string temp = row.Cells[0].Text;
    //        string thamchieu = row.Cells[1].Text;
    //        string ma = cldao.LayMaTheoTen(thamchieu);
    //        Session["ThamChieu"] = ma;
    //        //int magdv = int.Parse(Session["MaGDV"].ToString());
    //        int magdv = 0;
    //        magdv = int.Parse(Request.Cookies["MaGDV"].Value);
    //        int pub = gdvdao.LayMaPub(magdv);
    //        //bool kt = cldao.KiemTraTruyCap(pub, ma);
    //        bool kt = CheckPub(magdv, ma);
    //        if (kt == true)
    //        {
    //            //Response.Redirect("~/Pages/ManageClaim.aspx?Claim=" + ma);
    //            //Response.Redirect("~/Pages/InformationForm.aspx?Reference=" + ma);
    //            Response.Redirect("~/Pages/ClaimDetail1.aspx?Ref=Cover");
    //        }
            
    //        // Response.Redirect("~/Pages/InformationForm.aspx?1v5tdadefojhwty");
    //    }
    //}

    //protected void btnView_Click(object sender, EventArgs e)
    //{
    //    int level = int.Parse(drSort.SelectedItem.Value.ToString());
    //    System.Data.DataTable dt = new System.Data.DataTable();
    //    dt = cldao.SelectLevel(level);
    //    if (dt.Rows.Count > 0)
    //    {
    //        grDSClaim.DataSource = dt;
    //        grDSClaim.DataBind();
    //    }
    //}

    //protected void btnPending_Click(object sender, EventArgs e)
    //{
    //    System.Data.DataTable dt = cldao.SelectPending();
    //    if (dt.Rows.Count > 0)
    //    {
    //        grDSClaim.DataSource = dt;
    //        grDSClaim.DataBind();
    //    }
    //}

    //protected void btnAll_Click(object sender, EventArgs e)
    //{
    //    loadDS();
    //}

    //protected void btnClosed_Click(object sender, EventArgs e)
    //{
    //    System.Data.DataTable dt = cldao.SelectClosed();
    //    if (dt.Rows.Count > 0)
    //    {
    //        grDSClaim.DataSource = dt;
    //        grDSClaim.DataBind();
    //    }
    //}

    //protected void btnUprate_Click(object sender, EventArgs e)
    //{
    //    cldao.UpdateAutoTangRate();
    //    loadPending();
    //}

    //protected void btnDownrate_Click(object sender, EventArgs e)
    //{
    //    cldao.UpdateAutoGiamRate();
    //    loadPending();
    //}

    //protected void btnXemDonViBH_Click(object sender, EventArgs e)
    //{
    //    string ma = drDonViBH.SelectedItem.ToString();
    //    loadTheoMaHoa(ma);
    //}

    //protected void btnViewStatus_Click(object sender, EventArgs e)
    //{
    //    int ma = int.Parse(drStatus.SelectedItem.Value.ToString());
    //    loadTheoStatus(ma);
    //}
    //void loadGDV()
    //{
    //    GiamDinhVienDAO gdv = new GiamDinhVienDAO();
    //    drFollower.DataSource = gdv.DanhSachGiamDinhVien();
    //    drFollower.DataTextField = "TenGDV";
    //    drFollower.DataValueField = "ID_GDV";
    //    drFollower.DataBind();
    //}

    //protected void btnFollower_Click(object sender, EventArgs e)
    //{
    //    if (this.IsPostBack)
    //    {
    //        DataTable dt = new DataTable();
    //        //int idgdv = int.Parse(drFollower.SelectedItem.Value.ToString());
    //        string follower = drFollower.SelectedItem.ToString();
    //        dt = cldao.DSClaimTheoFollower(follower);
    //        if (dt.Rows.Count > 0)
    //        {
    //            grDSClaim.DataSource = dt;
    //            grDSClaim.DataBind();
    //            grDSClaim.Visible = true;
    //        }
    //        else
    //            grDSClaim.Visible = false;
    //    }
    //}

    //protected void grDSClaim_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    //{
    //    e.Cancel = true;
    //    grDSClaim.EditIndex = -1;
    //    loadPending();
    //}

    //protected void grDSClaim_RowUpdating(object sender, GridViewUpdateEventArgs e)
    //{
    //    GridViewRow row = grDSClaim.Rows[e.RowIndex];
    //    TextBox txtdocs = row.Cells[6].Controls[0] as TextBox;
    //    string tenclaim = grDSClaim.DataKeys[e.RowIndex].Value.ToString();
    //    string doc = txtdocs.Text;
    //    TextBox txtngay = row.Cells[4].Controls[0] as TextBox;
    //    TextBox txtRate = row.Cells[8].Controls[0] as TextBox;
    //    TextBox txtbrief = row.Cells[2].Controls[0] as TextBox;
    //    string ngay = txtngay.Text;
    //    DropDownList drStatus =
    //              (DropDownList)row.FindControl("drStatus");
    //    int giaidoan = int.Parse(drStatus.SelectedItem.Value.ToString());
    //    int rate = int.Parse(txtRate.Text);
    //    string brief = txtbrief.Text;
    //    DropDownList drGDV1 = (DropDownList)row.FindControl("drGDV1");
    //    string follower = drGDV1.SelectedItem.ToString();

    //}

    //protected void grDSClaim_RowEditing(object sender, GridViewEditEventArgs e)
    //{
    //    grDSClaim.EditIndex = e.NewEditIndex;
    //    loadPending();
    //}

    //protected void grDSClaim_RowDataBound(object sender, GridViewRowEventArgs e)
    //{
    //    if (e.Row.RowType == DataControlRowType.DataRow)
    //    {
    //        if ((e.Row.RowState & DataControlRowState.Edit) > 0)
    //        {
    //            DropDownList drStatus = (DropDownList)e.Row.FindControl("drStatus");
    //            drStatus.DataSource = gddao.DSGiaiDoan();
    //            drStatus.DataTextField = "TenGiaiDoan";
    //            drStatus.DataValueField = "ID_GiaiDoanHoanThanh";
    //            drStatus.DataBind();
    //            DataRowView dr = e.Row.DataItem as DataRowView;
    //            drStatus.SelectedValue = dr["TenGiaiDoan"].ToString();

    //            DropDownList drGDV1 = (DropDownList)e.Row.FindControl("drGDV1");
    //            drGDV1.DataSource = gdvdao.DanhSachGiamDinhVien();
    //            drGDV1.DataTextField = "TenGDV";
    //            drGDV1.DataValueField = "ID_GDV";
    //            drGDV1.DataBind();
    //            DataRowView drgdv = e.Row.DataItem as DataRowView;
    //            drGDV1.SelectedValue = drgdv["Follower"].ToString();

    //        }
    //    }
    //}
</script>





<div>
    <form runat="server">


        <asp:gridview id="grDSClaim" runat="server" width="99%"
            backcolor="White" bordercolor="#003300" borderstyle="None" borderwidth="1px"
            cellpadding="3" horizontalalign="Center" autogeneratecolumns="False" CssClass="webGrid"> 
            <AlternatingRowStyle HorizontalAlign="Left" VerticalAlign="Middle" />
            <Columns>
             <asp:TemplateField HeaderText="No.">
                <ItemTemplate> 
                    <%#Container.DataItemIndex+1 %>
                            </ItemTemplate> 
                    <HeaderStyle Font-Bold="True" HorizontalAlign="Center" 
                     VerticalAlign="Middle" />
                    <ItemStyle Width="3%" HorizontalAlign="Center" />
                </asp:TemplateField>
                <asp:BoundField DataField="TenClaim" HeaderText="Case Name" >
                <ControlStyle Width="100px" />
                <HeaderStyle Font-Bold="True" HorizontalAlign="Center" />
                <ItemStyle Width="12%" />
                </asp:BoundField>
                <asp:BoundField DataField="Brief" HeaderText="Brief">
                <HeaderStyle HorizontalAlign="Center" Font-Bold="True" />
                </asp:BoundField>
                <asp:BoundField DataField="TenKhachHang" HeaderText="Insured" >
                <ControlStyle Width="150px" />
                <HeaderStyle Font-Bold="True" />
                <ItemStyle Width="15%" />
                </asp:BoundField>
                <asp:BoundField DataField="AssignedDate" HeaderText="AssignedDate" >
                <ControlStyle Width="30px" />
                <HeaderStyle Font-Bold="True" />
                <ItemStyle Width="8%" HorizontalAlign="Center" Font-Bold="False" />
                </asp:BoundField>
             <%--   <asp:BoundField DataField="TenGiaiDoan" HeaderText="Status">
                <HeaderStyle Font-Bold="True" />
                <ItemStyle Width="10%" Font-Bold="False" />
                </asp:BoundField>--%>
                <asp:TemplateField HeaderText="Status">
                 <HeaderStyle HorizontalAlign="Left" Width="10%" />
                <ItemStyle HorizontalAlign="Left" />
                 <ItemTemplate> <%#Eval("TenGiaiDoan")%></ItemTemplate>
                 <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" >               
                    </asp:DropDownList>                               
                    </EditItemTemplate>       
                </asp:TemplateField>
                <asp:BoundField DataField="Docs" HeaderText="Progress" >
                <ControlStyle Width="150px" />
                <HeaderStyle Font-Bold="True" />
                <ItemStyle Width="15%" Font-Bold="False" />
                </asp:BoundField>
                  <asp:TemplateField HeaderText="Follower">
                 <HeaderStyle HorizontalAlign="Left" Width="10%" />
                <ItemStyle HorizontalAlign="Left" />
                 <ItemTemplate> <%#Eval("Follower")%></ItemTemplate>
                 <EditItemTemplate>
                    <asp:DropDownList ID="drGDV1" runat="server" >               
                    </asp:DropDownList>                               
                    </EditItemTemplate>       
                </asp:TemplateField>
               <%-- <asp:BoundField DataField="Follower" HeaderText="Follower">
                <HeaderStyle Font-Bold="True" />
                <ItemStyle HorizontalAlign="Center" Width="10%" Font-Bold="False" />
                </asp:BoundField>--%>
                <asp:BoundField DataField="Rate" HeaderText="Rate">
                <HeaderStyle Font-Bold="True" />
                <ItemStyle HorizontalAlign="Center" />
                </asp:BoundField>
                <asp:CommandField ButtonType="Image" HeaderText="Edit" ShowEditButton="True" 
                    EditImageUrl="~/images/edit_icon.png" />
                <asp:CommandField HeaderText="Detail" ShowSelectButton="True" 
                    ButtonType="Image" SelectImageUrl="~/images/detail_icon.png">
                <ItemStyle Width="50px" HorizontalAlign="Center" />
                </asp:CommandField>
            </Columns>
            <EditRowStyle Font-Names="Tahoma" ForeColor="#003300" HorizontalAlign="Left" 
                VerticalAlign="Top" />
            <FooterStyle BackColor="White" ForeColor="#000066" />
            <HeaderStyle BackColor="#006600" BorderColor="#003300" Font-Bold="True" 
                ForeColor="White" Font-Names="Times New Roman" Font-Size="18px" />
            <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
            <RowStyle HorizontalAlign="Left" 
                VerticalAlign="Top" Font-Bold="False" Font-Names="Times New Roman" 
                Font-Size="14px" BorderColor="#003300" />
            <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#F1F1F1" />
            <SortedAscendingHeaderStyle BackColor="#007DBB" />
            <SortedDescendingCellStyle BackColor="#CAC9C9" />
            <SortedDescendingHeaderStyle BackColor="#00547E" />
        </asp:gridview>
        <asp:label id="lblThongBao" runat="server" visible="False"></asp:label>

    </form>
</div>
